package ngat.oss;

import ngat.message.OSS.*;
import ngat.util.logging.*;
import ngat.phase2.*; 
import ngat.instrument.*;
import ngat.phase2.nonpersist.*;

import java.util.*;
import java.io.*;

import jyd.dbms.*;
import jyd.storable.*;
import jyd.collection.*;

/**
 * Action: Sent by USR to remove a PI User from a Proposal.
 * @author S.N.Fraser
 * $Id: DELETE_USERImpl.java,v 1.2 2007/07/05 11:48:51 snf Exp $
 */
public class DELETE_USERImpl extends TransactionImpl {
    
    /** The path used to locate the Proposal in the OSS database. */
    protected Path userPath;

    /** Create a DELETE_USERImpl for the supplied request.*/
    public DELETE_USERImpl(DELETE_USER request) {
	super(request);
	this.userPath = request.getUserPath();
    }
    
    /**
     *Removes the specified Userfrom the specified TAGs list.
     * @return Boolean to indicate success.
     */
    public TRANSACTION_DONE exec() { 

	Transaction t = null;
	try {
	    t = Transaction.current();
	    
	    Tag tag  = OSS_Utilities.fetchTag(userPath);

	    if (tag == null)	
		return error(TRANSACTION.PATH_RESOLUTION_ERROR,
			     "No such owner Tag ["+userPath.getTagByName()+"] found");
	    
	    
	    
	    User user = OSS_Utilities.fetchUser(userPath);
	    
	    if (user == null)
		return error(TRANSACTION.PATH_RESOLUTION_ERROR,
			     "No such User ["+userPath.getUserByName()+"] found");
	    
	    tag.deleteUser(user);
	    
	    DELETE_USER_DONE done = new DELETE_USER_DONE(id); 
	    done.setSuccessful(true);
	    done.setRemoved(true);
	    return done;
	    
	} finally {
	    t.commit();
	}
    }
    
}

/** $Log: DELETE_USERImpl.java,v $
/** Revision 1.2  2007/07/05 11:48:51  snf
/** checkin
/**
/** Revision 1.1  2007/03/06 07:46:45  snf
/** Initial revision
/**
/** Revision 1.1  2006/11/27 08:45:00  snf
/** Initial revision
/**
/** Revision 1.1  2001/02/23 18:51:14  snf
/** Initial revision
/** */
